from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
import math


class MyPagination(PageNumberPagination):
    page_size = 5

    def get_paginated_response(self, data):
        return Response({
            'errCode': 0,
            'errMsg': '成功',
            'data': {
                'links':
                    {
                        'next': self.get_next_link(),
                        'previous': self.get_previous_link()
                    },
                'count': self.page.paginator.count,
                'current_page': self.page.number,
                'total_pages': math.ceil(self.page.paginator.count/self.page_size),
                'results': data,
            }
        }
        )
